package com.tianji.aigc.controller;

import com.tianji.aigc.service.ChatSessionService;
import com.tianji.aigc.vo.ChatSessionVO;
import com.tianji.aigc.vo.SessionDetailVO;
import com.tianji.aigc.vo.SessionVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 会话session 控制器
 * @author zgp
 * @version V1.0
 * @date 2025-04-21 12:18
 */
@Slf4j
@RestController
@RequestMapping("/session")
@RequiredArgsConstructor
public class SessionController {
    private final ChatSessionService chatSessionService;

    /**
     * 会话创建
     * @param num 热门问题数量
     * @return
     */
    @PostMapping
    public SessionVO createSession(@RequestParam(value = "n", defaultValue = "3") Integer num){
        log.info("创建会话");
        return chatSessionService.createSession(num);
    }

    /**
     * 获取热门问题列表
     * @param num 数量
     * @return
     */
    @GetMapping("/hot")
    public List<SessionVO.Example> hotQuestions(@RequestParam(value = "n", defaultValue = "3") Integer num){
        log.info("获取热门问题列表");
        return chatSessionService.hotQuestions(num);
    }

    /**
     * 查询会话详情
     * @param sessionId 会话id
     * @return
     */
    @GetMapping("/{sessionId}")
    public List<SessionDetailVO> getSessionDetail(@PathVariable("sessionId") String sessionId){
        log.info("查询会话详情");
        return chatSessionService.getSessionDetail(sessionId);
    }

    /**
     * 查询历史会话列表
     * @return
     */
    @GetMapping("/history")
    public Map<String, List<ChatSessionVO>> history(){
        log.info("查询历史会话列表");
        return chatSessionService.history();
    }

    @PutMapping("/history")
    public void modifyHistorySessionTitle(@RequestParam("sessionId") String sessionId,
                                  @RequestParam("title") String title){
        log.info("修改会话标题");
        chatSessionService.modifyHistorySessionTitle(sessionId, title);
    }

    @DeleteMapping("/history")
    public void deleteHistorySession(@RequestParam("sessionId") String sessionId){
        log.info("删除历史会话");
        chatSessionService.deleteHistorySession(sessionId);
    }

}
